<!--
 * @Description: 招聘 岗位审核列表
 * @Author: liyujie
 * @Date: 2021/09/22
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/09/22
-->
<template>
    <PageLayout title="岗位审核">
        <!-- 筛选-->
        <template slot="filter">
            <div class="filter-item">
                <div class="filter-item__title">
                    企业名称
                </div>
                <el-input
                    placeholder="企业名称"
                    v-model="filterData.company_name"
                    suffix-icon="el-icon-search"
                    clearable
                    size="medium"
                    @keydown.enter.native="getTableData(1)"
                />
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    工作城市
                </div>
                <el-input
                    placeholder="工作城市"
                    v-model="filterData.city_name"
                    suffix-icon="el-icon-search"
                    clearable
                    size="medium"
                    @keydown.enter.native="getTableData(1)"
                />
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    岗位名称
                </div>
                <el-input
                    placeholder="岗位名称"
                    v-model="filterData.title"
                    suffix-icon="el-icon-search"
                    clearable
                    size="medium"
                    @keydown.enter.native="getTableData(1)"
                />
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    招聘类型
                </div>
                <el-select
                    v-model="filterData.type"
                    filterable
                    size="medium"
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in typeList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    状态
                </div>
                <el-select
                    v-model="filterData.verify"
                    filterable
                    size="medium"
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in statusList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    提交时间
                </div>
                <el-date-picker
                    v-model="dateTimeRange"
                    type="datetimerange"
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :default-time="['00:00:00', '23:59:59']"
                    size="medium"
                    style="width: 360px"
                    value-format="timestamp"
                    @change="getTableData(1)"
                />
            </div>
            <div class="filter-item">
                <el-button
                    type="primary"
                    size="small"
                    class="query-button"
                    @click="getTableData(1)"
                >
                    查询
                </el-button>
            </div>
        </template>
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            ref="tempLateName"
            class="data-table"
            v-loading="tableLoading"
        >
            <el-table-column
                label="序号"
                align="center"
                width="80"
                type="index"
            />
            <el-table-column
                prop="company_name"
                label="公司名称"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="company_name"
                label="招聘类型"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.type === 1">实习生</span>
                    <span v-if="scope.row.type === 2">毕业校招</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="position_name"
                label="职位类别"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="title"
                label="职位名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                label="薪资范围"
                align="left"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div v-if="scope.row.money_time_type === 1">
                        {{ scope.row.money_min }} - {{ scope.row.money_max }} 元/日
                    </div>
                    <div v-if="scope.row.money_time_type === 2">
                        {{ scope.row.money_min / 1000 }} - {{ scope.row.money_max / 1000 }} K/月
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="工作城市"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    {{ scope.row.address_province_name }}
                    {{ scope.row.address_city_name }}
                    {{ scope.row.address_county_name }}
                </template>
            </el-table-column>
            <el-table-column
                label="审核状态"
                align="center"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div class="status-wrapper">
                        <div
                            class="status-dot"
                            :class="['status-dot', scope.row.verify === 1 ? 'success' : scope.row.verify === 0 ? 'warning' : 'danger']"
                        />
                        <div>{{ scope.row.verify | statusFilter }}</div>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="提交时间"
                align="left"
                :formatter="emptyFormatter"
                width="180"
            >
                <template slot-scope="scope">
                    {{ scope.row.submit_time * 1000 | dateFormatter('yyyy-MM-dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="left"
                width="120"
            >
                <template slot-scope="scope">
                    <div class="option-btn-group">
                        <el-button
                            type="text"
                            size="medium"
                            @click="handleRoute('recruitPostDetail', {recruit_no: scope.row.recruit_no})"
                        >
                            {{ scope.row.verify ? '查看' : '审核' }}
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <template slot="pagination">
            <div/>
            <el-pagination
                layout="total, prev, pager, next, jumper"
                background
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </template>
    </PageLayout>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'RecruitPostList',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                recruit_no: '',
                company_name: '',
                city_name: '',
                title: '',
                type: 99,
                verify: 99,
                submit_start_time: '',
                submit_end_time: ''
            },
            dateTimeRange: null,
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            typeList: [
                {label: '全部', value: 99},
                {label: '实习生', value: 1},
                {label: '毕业校招', value: 2},
            ],
            statusList: [
                {label: '全部', value: 99},
                {label: '待审核', value: 0},
                {label: '已通过', value: 1},
                {label: '未通过', value: -1},
            ]
        };
    },
    computed: {},
    watch: {},
    filters: {
        statusFilter(val) {
            switch (val) {
                case 0:
                    return '待审核';
                case 1:
                    return '已通过';
                case -1:
                    return '未通过';
                default:
                    return '--';
            }
        },
    },
    mounted() {
        this.init();
    },

    methods: {
        init() {
            let filterData = JSON.parse(sessionStorage.getItem('RECRUIT_POST_QUERY'));

            this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '人力资源'}, {title: '岗位审核'}]);
            this.authResult = this.$route.meta.authResult;
            if (filterData) {
                this.filterData = filterData;
                this.page.now_page = Number(sessionStorage.getItem('RECRUIT_POST_PAGE_NO'));
                this.dateTimeRange = JSON.parse(sessionStorage.getItem('RECRUIT_POST_DATE'));
                sessionStorage.removeItem('RECRUIT_POST_QUERY');
                sessionStorage.removeItem('RECRUIT_POST_PAGE_NO');
                sessionStorage.removeItem('RECRUIT_POST_DATE');
            }
            this.filterData.recruit_no = this.$route.query.recruit_no ? this.$route.query.recruit_no : '';
            this.getTableData();
        },

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.submit_start_time = this.dateTimeRange ? this.dateTimeRange[0] / 1000 : '';
            params.submit_end_time = this.dateTimeRange ? this.dateTimeRange[1] / 1000 : '';
            params.page_id = page || this.page.now_page;
            this.$post('/student/work_recruit%5Cshop_apply%5Cget_audit_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: res.msg
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
            sessionStorage.setItem('RECRUIT_POST_QUERY', JSON.stringify(this.filterData));
            sessionStorage.setItem('RECRUIT_POST_PAGE_NO', this.page.now_page);
            sessionStorage.setItem('RECRUIT_POST_DATE', JSON.stringify(this.dateTimeRange));
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },
    }
};
</script>
